﻿using UnityEngine;
using System.Collections;

public class LineMover : Mover
{
    public Vector3 Dir;
    public int MoveDistance;
    public int Speed;
    public  long StartTime;
    public Vector3 StartPos;

    GameScene curScene;
    public override void Start(Unit unit)
    {
        this.Dir.Normalize();
        curScene = SGLib.Scene.SceneManager.Instance.Cur<GameScene>();
        base.Start(unit);
        unit.transform.position = StartPos;
    }
    public override void ServerUpdate(long dt)
    {
        if (!isStart) return;
        int moveTime = (int)(curScene.ServerTime - StartTime);
        Vector3 move = this.Dir * this.Speed * moveTime;
        mUnit.transform.position = (StartPos + (move / 1000f));
        //Debug.Log(this.Speed.ToString()+"  "+moveTime.ToString()+"   "+move.magnitude);
        if (Vector3.Distance(mUnit.transform.position, this.StartPos)>MoveDistance)
        {
            isStart = false;
        }
    }

}
